package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.mapper.OrderGoodsMapper;
import com.rongke.model.OrderGoods;
import com.rongke.service.OrderGoodsService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * @OrderGoodsController
 * @商品订单详情Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/orderGoods")
@Transactional
@CrossOrigin
public class OrderGoodsController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private OrderGoodsService orderGoodsService;

    /**
     * @添加商品订单详情
     * @param orderGoods
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addOrderGoods(@RequestBody OrderGoods orderGoods){
        log.debug("添加商品订单详情");
        orderGoods.setGmtDatetime(new Date());
        orderGoodsService.insert(orderGoods);
        return JsonResp.ok(orderGoods);
    }

    /**
     * @修改商品订单详情
     * @param orderGoods
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateOrderGoods(@RequestBody OrderGoods orderGoods){
        log.debug("修改商品订单详情");
        orderGoods.setUptDatetime(new Date());
        orderGoodsService.updateById(orderGoods);
        return JsonResp.ok(orderGoods);
    }
    /**
     * @根据id查找商品订单详情
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectOrderGoods(Long id){
        log.debug("查找商品订单详情");
        OrderGoods orderGoods = orderGoodsService.selectById(id);
        return JsonResp.ok(orderGoods);
    }

    /**
     * @根据条件查找商品订单详情
     * @param orderGoods
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
    public JsonResp selectOrderGoodsByCondition(@RequestBody OrderGoods orderGoods){
        log.debug("根据条件查找商品订单详情");
        if(orderGoods==null)
            return JsonResp.toFail("参数不能为空");
        List<OrderGoods> orderGoodsList=orderGoodsService.selectByCondition(orderGoods);
        return JsonResp.ok(orderGoodsList);
    }

    /**
     * 根据订单id获取订单商品信息详情
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/selectOrderGoodsByOrderId",method = RequestMethod.GET)
    public JsonResp selectOrderGoodsByOrderId(Long orderId){
        log.debug("根据订单id获取订单商品信息详情");
        List<OrderGoods> ogList=orderGoodsService.selectOrderGoodsByOrderId(orderId);
        return JsonResp.ok(ogList);
    }

}
